package com.java.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.java.entity.ExAccount;
import com.java.mapper.ExAccountMapper;
import com.java.service.AccountService;
import com.java.util.MyCons;
import com.java.util.MyMap;
import com.java.util.resp.BaseRespone;
import com.java.util.resp.TableRespone;
import com.java.util.servlet.ServletUtil;

@Service
public class AccountServiceImpl implements AccountService {
	
	@Autowired private ExAccountMapper accountMapper;

	@Override
	public BaseRespone saveAuth(String openId, String nick, String logo) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ExAccount getAccountByOpenId(String openId) {
		ExAccount account = accountMapper.selectByInfo(new ExAccount().setAccountOpenId(openId));
		if(null != account) {
			ServletUtil.getSession().setAttribute(MyCons.USER_ROLE, account);
		}
		return account;
	}

	@Override
	public ExAccount getAccount(String accountId) {
		return accountMapper.selectByKey(accountId);
	}

	@Override
	public TableRespone getAccountList(int page, int size) {
		MyMap mm = new MyMap();
		int offset = TableRespone.getOffset(page, size);
		List<ExAccount> list = accountMapper.selectAll(mm, offset, size);
		List<ExAccount> count = accountMapper.selectAll(mm, 0, 0);
		return new TableRespone(list, count.size());
	}

}
